package com.dxl.base.util;

import com.dxl.base.Result;
import com.dxl.base.Results;
import com.dxl.base.common.GlobalConstant;
import com.dxl.coreutil.FileWriteUtil;
import com.dxl.coreutil.MarkDown2HtmlWrapper;
import com.dxl.coreutil.MarkdownEntity;

import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

/**
 * <b> .md文件渲染成html
 * </b><br><br><i>Description</i> :
 * <br> Author : dxl
 * <br> Date : 2019/10/3 19:49
 */
public class MdToHtml {
    public static Result mdToHtml(String filePath,String cssPathName,String savePath,String saveName){
        MarkdownEntity html = null;
        try {
            html = MarkDown2HtmlWrapper.ofFile(filePath,cssPathName);
        } catch (IOException e) {
            //e.printStackTrace();
            return Results.failure("渲染失败:(");
        }
        InputStream is = new ByteArrayInputStream(html.toString().getBytes());
        try {
            FileWriteUtil.saveFileByStream(is,savePath,saveName,"html");
        } catch (FileNotFoundException e) {
            return Results.failure("渲染失败:(");
        }
        return Results.success("渲染成功:)");
    }

}
